class Solution {
public:
    int maxSubArray(int A[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		if (A == NULL || n == 0) {
			return 0;
		}
		int last = 0;
		int ans = A[0];
		for (int i = 0; i < n; ++i) {
			int cur = last < 0 ? A[i] : last + A[i];
			ans = max(ans, cur);
			last = cur;
		}
		return ans;

    }
};